package com.hopedove.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hadilq.liveevent.LiveEvent
import kotlinx.coroutines.launch

open class BaseViewModel : ViewModel() {

    protected val _navigation = LiveEvent<Class<*>>()
    val navigation: LiveData<Class<*>> = _navigation

    protected val _toastText = LiveEvent<String>()
    val toastText: LiveData<String> = _toastText

    protected val _loading = LiveEvent<Boolean>()
    val loading: LiveData<Boolean> = _loading

    protected val _commonEvent = LiveEvent<CommonEvent<*>>()
    val commonEvent: LiveData<CommonEvent<*>> = _commonEvent

    protected fun startLoading() {
        _loading.value = true
    }

    protected fun dismissLoading() {
        _loading.value = false
    }

    protected fun <T> navigateTo(destination: Class<T>) {
        _navigation.value = destination
    }

    open fun load() = viewModelScope.launch {}
}


data class CommonEvent<T>(val name: String, val data: T)